package project.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


public class MainActivity extends Activity
{
    private TextView text1;
    
    private final String NAMESPACE = "http://tempuri.org/";
    private final String URL = "http://179.30.91.158/Servicios/Horas/Service1.svc?wsdl";
    private final String SOAP_ACTION = "http://tempuri.org/IService1/GetTareas";
    private final String METHOD_NAME = "GetTareas";
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        InicializeComponents();
        text1.setText("HOLA");
        
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        //RequestTest requestTest = new RequestTest();
        //requestTest.Cedula = "1111111";
        //requestTest.ID = 1;
        //requestTest.Nombre = "Matias";
        
        //PropertyInfo propInfo=new PropertyInfo();
        //propInfo.setName("RequestTest");
        //propInfo.setValue(requestTest);
        //propInfo.setType(requestTest.getClass());

        //request.addProperty(propInfo);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        //envelope.addMapping(NAMESPACE, "RequestTest", requestTest.getClass());
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
            response.getAttributeCount();
            String value = "";
            for (int i = 0; i < response.getPropertyCount(); i++) 
            {
                Object property = response.getProperty(i);
                value +=  property.toString();
            }         
            text1.setText("Consumiendo Servicio carga de horas: " + value);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void InicializeComponents()
    {
        text1 = (TextView) findViewById(R.id.info);
    }
}
